package com.wzcl.app.dao.model;

import com.wzcl.app.dao.model.common.Base;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

@Data
@Entity
@Table(name = "Cart",
        indexes = {
                @Index(columnList = "userPhone"),
                @Index(columnList = "spec")
        }
)
@ApiModel(value = "购物车表")
@EntityListeners(AuditingEntityListener.class)
public class Cart implements Base {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @ApiModelProperty(value = "用户Id")
    private Integer userId;

    @ApiModelProperty(value = "用户手机")
    private String userPhone;

    @CreatedDate
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @Transient
    @ApiModelProperty("课程信息")
    private Course course;

    @ApiModelProperty(value = "商品")
    @ManyToOne(cascade = CascadeType.MERGE)
    @JoinColumn(name = "commodityId")
    private Commodity commodity;

    @ApiModelProperty(value = "商品")
    private String spec;

    @ApiModelProperty(value = "状态")
    private Integer state;

    @ApiModelProperty(value = "订单Id,用于订单取消时重新填充购物车")
    private Integer orderId;
}